package com.mofang.ticketing.base.serve.mq.listener;

import com.mofang.ticketing.base.serve.mq.listener.voucher.message.VoucherCreateMessage;
import com.mofang.ticketing.base.serve.mq.listener.voucher.message.VoucherExpireRefundDelayMessage;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.mq.rabbit.config.voucher.VoucherBindEnum;
import com.mofang.ticketing.common.mq.rabbit.util.RabbitUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author LGC
 */
@Api(tags = "test")
@RestController
public class TestController {

    @Resource
    private RabbitUtil rabbitUtil;

    @ApiOperation(value = "普通-凭证生成")
    @GetMapping("/test")
    public Result<String> test() {
        VoucherCreateMessage voucherCreateMessage = new VoucherCreateMessage();
        voucherCreateMessage.setOrderNo("order12322222222");
        voucherCreateMessage.setChannelId(1L);
        VoucherCreateMessage.Customer customer = new VoucherCreateMessage.Customer();
        customer.setCustomerId(1L);
        customer.setCustomerPhone("123333");
        customer.setCertificateNo("222222222");
        List<VoucherCreateMessage.Customer> list = new ArrayList<>();
        list.add(customer);
        voucherCreateMessage.setCustomerList(list);
        rabbitUtil.send(VoucherBindEnum.VOUCHER_CREATE, voucherCreateMessage);
        return Result.success();
    }

    @ApiOperation(value = "凭证过期可退-延时")
    @GetMapping("/test2")
    public Result<String> test2() {
        VoucherExpireRefundDelayMessage voucherExpireRefundDelayMessage = new VoucherExpireRefundDelayMessage();
        voucherExpireRefundDelayMessage.setVoucherNo(UUID.randomUUID().toString());
        rabbitUtil.sendDelay(VoucherBindEnum.VOUCHER_EXPIRE_REFUND_DELAY, voucherExpireRefundDelayMessage, 10);
        return Result.success();
    }

}
